package com.asj.house.service.impl;

import com.asj.house.entity.HouseNotice;
import com.asj.house.mapper.HouseNoticeMapper;
import com.asj.house.returns.RespCode;
import com.asj.house.returns.RespEntity;
import com.asj.house.service.HouseNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.awt.geom.QuadCurve2D;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 公告表 服务实现类
 * </p>
 *
 * @author asj
 * @since 2021-03-04
 */
@Service
public class HouseNoticeServiceImpl extends ServiceImpl<HouseNoticeMapper, HouseNotice> implements HouseNoticeService {

    @Override
    public RespEntity<List<HouseNotice>> listHouseNotice() {
        QueryWrapper<HouseNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(HouseNotice::getDeleted, 0);

        List<HouseNotice> houseNoticeList = baseMapper.selectList(queryWrapper);
        houseNoticeList = houseNoticeList.stream()
                .sorted(Comparator.comparing(HouseNotice::getId).reversed())
                .limit(8)
                .collect(Collectors.toList());

        return new RespEntity<>(RespCode.SUCCESS, houseNoticeList);
    }
}
